Failure
1624
21
200
293
168
23
242.92
20578.67
Report
This is a report on 1624 car failures.
The average labor cost was 242.9180111.
The average material cost was 179.3948276.
This report was generated on 4月 06, 2022.
Created by: Dashboard Viz by CMUH BDC
Confidential: HIGHLY!
---
title: "HL's Dashboard"
output:
flexdashboard::flex_dashboard:
orientation: rows
vertical_layout: fill
social: [ "twitter", "facebook", "menu"]
source_code: embed
---
```{r setup, include=FALSE}
#設定環境 如果無法設定套件環境,請下載套件,利用install.packages("XXX")指令
library(flexdashboard)
library(knitr)
library(DT)
library(rpivotTable)
library(ggplot2)
library(plotly)
library(dplyr)
library(openintro)
library(highcharter)
library(ggvis)
# 當圖形帶有中文,請安裝此套件
knitr::opts_chunk$set(fig.showtext=TRUE)
library(showtext)
showtext_auto()
```
```{r}
#帶入資料
data <- read.csv("./vehicle.csv")
```
```{r}
#預先指定顏色
mycolors <- c("blue", "#FFC125", "darkgreen", "darkorange")
```
Interactive Data Visualization
=====================================
Row
-------------------------------------
### Car Failure Analysis
```{r}
#顯示文字方塊
valueBox(paste("Failure"),
color = "warning")
```
### Car Failures in US
```{r}
#顯示文字方塊,帶入數值
valueBox(length(data$State),
icon = "fa-user")
```
### **Labor Cost**
```{r}
#顯示計量表,並指定顏色範圍。lc代表工資labor cost。
gauge(round(mean(data$lc),
digits = 2),
min = 0,
max = 350,
gaugeSectors(success = c(0, 150),
warning = c(150, 300),
danger = c(300, 450),
colors = c("green", "yellow", "red")))
```
### Massachusetts
```{r}
#顯示文字方塊,帶入特定州別條件下的數值
valueBox(sum(data$State == "MA"),
icon = 'fa-building')
```
### California
```{r}
#顯示文字方塊,帶入特定州別條件下的數值
valueBox(sum(data$State == "CA"),
icon = 'fa-building')
```
### Texas
```{r}
#顯示文字方塊,帶入特定州別條件下的數值
valueBox(sum(data$State == "TX"),
icon = 'fa-building')
```
### Florida
```{r}
#顯示文字方塊,帶入特定州別條件下的數值
valueBox(sum(data$State == "FL"),
icon = 'fa-building')
```
Row
-------------------------------
### Failures By State
```{r}
#繪製各州別的汽車故障總數長條圖
p1 <- data %>%
group_by(State) %>% #依州別分群計算
summarise(count = n()) %>% #計算總數
plot_ly(x = ~reorder(State,count,desc), #X軸為州別,並依照數量遞減排序
y = ~count, #Y軸為州別
color = "red", #顏色為紅色
type = 'bar') %>% #圖形類別為長條圖
layout(xaxis = list(title = "Failures By State"), #X軸的名稱
yaxis = list(title = 'Count')) #Y軸的名稱
p1 #呼叫圖形
```
### Top States
```{r}
#繪製汽車故障總數大於50的州佔比甜甜圈圖
p2 <- data %>%
group_by(State) %>%
summarise(count = n()) %>%
filter(count>50) %>% # 篩選總數大於50
plot_ly(labels = ~State,
values = ~count,
marker = list(colors = mycolors)) %>% #指定顏色
add_pie(hole = 0.5) %>% #中間空圈大小
layout(xaxis = list(zeroline = F,
showline = F,
showticklabels = F,
showgrid = F),
yaxis = list(zeroline = F,
showline = F,
showticklabels=F,
showgrid=F))
p2
```
### FM Vs Mileage
```{r}
#繪製汽車故障車齡(fm)與總里程(Mileage)的長條圖
p3 <- plot_ly(data,
x = ~fm,
y = ~Mileage,
text = paste("FM:", data$fm, #註解裡要放的資訊
"Mileage:",
data$Mileage),
type = "bar") %>%
layout(xaxis = list(title="FM"),
yaxis = list(title = "Failure Mileage"))
p3
```
Row
------------------------------------
### Scatter Plot of Month Vs Mileage
```{r}
#繪製汽車故障車齡(fm)與總里程(Mileage)的點陣圖與趨勢線
p4 <- plot_ly(data, x=~fm) %>%
add_markers(y = ~Mileage,
text = ~paste("Mileage: ", Mileage),
showlegend = F) %>%
add_lines(y = ~fitted(loess(Mileage ~ fm)), #增加趨勢線
name = "Loess Smoother",
color = I("#FFC125"),
showlegend = T,
line = list(width=5)) %>%
layout(xaxis = list(title = "Month"),
yaxis = list(title = "Mileage"))
p4
```
### Box Plot of Top State
```{r}
#繪製汽車故障州別(State)與工資(lc)的盒狀圖
data %>%
group_by(State) %>%
ggvis(~State, ~lc, fill = ~State) %>%
layer_boxplots()
```
Map
========================================
### Map
```{r}
#繪製汽車故障州別(State)的地圖
car <- data %>%
group_by(State) %>%
summarize(total = n())
car$State <- abbr2state(car$State)
highchart() %>%
hc_title(text = "Car Failures in US") %>%
hc_subtitle(text = "Source: Vehiclefailure.csv") %>%
hc_add_series_map(usgeojson, car,
name = "State",
value = "total",
joinBy = c("woename", "State")) %>%
hc_mapNavigation(enabled = T)
```
Data Table
========================================
```{r}
#繪製汽車故障州別(State)的列表
datatable(data,
caption = "Failure Data",
rownames = T,
filter = "top",
options = list(pageLength = 25))
```
Pivot Table
=========================================
```{r}
#繪製汽車故障州別(State)的互動式樞紐分析圖
rpivotTable(data,
aggregatorName = "Count",
cols= "fm",
rows = "State",
rendererName = "Heatmap")
```
Summary {data-orientation=columns}
===========================================
Column
-----------------------------------
### Max Failure Month
```{r}
#車輛故障的最大車齡統計類別
valueBox(max(data$fm),
icon = "fa-user" )
```
### Average Labor cost
```{r}
#車輛故障的平均工資齡統計類別
valueBox(round(mean(data$lc),
digits = 2),
icon = "fa-area-chart")
```
### Average Mileage at Failure
```{r}
#車輛故障的平均總里程統計類別
valueBox(round(mean(data$Mileage), digits = 2),
icon = "fa-area-chart")
```
Column
---------------------------
Report
* This is a report on `r length(data$fm)` car failures.
* The average labor cost was `r mean(data$lc)`.
* The average material cost was `r mean(data$mc)`.
This report was generated on `r format(Sys.Date(), format = "%B %d, %Y")`.
About Report
========================================
Created by: Dashboard Viz by CMUH BDC
Confidential: HIGHLY!